from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-10-15 14:04:35.732114
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 15, Oct, 2022
Time: 14:04:41
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.7150
Nobs: 810.000 HQIC: -51.0365
Log likelihood: 10496.9 FPE: 5.59899e-23
AIC: -51.2369 Det(Omega_mle): 5.01360e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.295932 0.052549 5.632 0.000
L1.Burgenland 0.109010 0.035368 3.082 0.002
L1.Kärnten -0.106442 0.018833 -5.652 0.000
L1.Niederösterreich 0.210402 0.073974 2.844 0.004
L1.Oberösterreich 0.099677 0.070961 1.405 0.160
L1.Salzburg 0.250638 0.037676 6.652 0.000
L1.Steiermark 0.038412 0.049320 0.779 0.436
L1.Tirol 0.106337 0.040000 2.658 0.008
L1.Vorarlberg -0.058850 0.034392 -1.711 0.087
L1.Wien 0.059398 0.063275 0.939 0.348
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.063284 0.108773 0.582 0.561
L1.Burgenland -0.033683 0.073210 -0.460 0.645
L1.Kärnten 0.047778 0.038982 1.226 0.220
L1.Niederösterreich -0.172447 0.153120 -1.126 0.260
L1.Oberösterreich 0.385099 0.146884 2.622 0.009
L1.Salzburg 0.286665 0.077986 3.676 0.000
L1.Steiermark 0.105823 0.102088 1.037 0.300
L1.Tirol 0.313563 0.082797 3.787 0.000
L1.Vorarlberg 0.025420 0.071188 0.357 0.721
L1.Wien -0.014874 0.130973 -0.114 0.910
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189768 0.026977 7.034 0.000
L1.Burgenland 0.090147 0.018157 4.965 0.000
L1.Kärnten -0.008445 0.009668 -0.873 0.382
L1.Niederösterreich 0.264562 0.037975 6.967 0.000
L1.Oberösterreich 0.126424 0.036429 3.470 0.001
L1.Salzburg 0.047877 0.019341 2.475 0.013
L1.Steiermark 0.016912 0.025319 0.668 0.504
L1.Tirol 0.094402 0.020535 4.597 0.000
L1.Vorarlberg 0.059385 0.017655 3.364 0.001
L1.Wien 0.120006 0.032483 3.694 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.109838 0.027641 3.974 0.000
L1.Burgenland 0.044246 0.018604 2.378 0.017
L1.Kärnten -0.016108 0.009906 -1.626 0.104
L1.Niederösterreich 0.192882 0.038911 4.957 0.000
L1.Oberösterreich 0.294123 0.037326 7.880 0.000
L1.Salzburg 0.115264 0.019818 5.816 0.000
L1.Steiermark 0.099644 0.025943 3.841 0.000
L1.Tirol 0.116338 0.021040 5.529 0.000
L1.Vorarlberg 0.070677 0.018090 3.907 0.000
L1.Wien -0.027300 0.033283 -0.820 0.412
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.126965 0.050172 2.531 0.011
L1.Burgenland -0.051589 0.033769 -1.528 0.127
L1.Kärnten -0.040516 0.017981 -2.253 0.024
L1.Niederösterreich 0.169965 0.070628 2.406 0.016
L1.Oberösterreich 0.137114 0.067751 2.024 0.043
L1.Salzburg 0.285047 0.035972 7.924 0.000
L1.Steiermark 0.034162 0.047089 0.725 0.468
L1.Tirol 0.165046 0.038191 4.322 0.000
L1.Vorarlberg 0.104251 0.032836 3.175 0.001
L1.Wien 0.071697 0.060412 1.187 0.235
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.060334 0.039756 1.518 0.129
L1.Burgenland 0.038840 0.026758 1.452 0.147
L1.Kärnten 0.050734 0.014248 3.561 0.000
L1.Niederösterreich 0.225790 0.055965 4.035 0.000
L1.Oberösterreich 0.282397 0.053685 5.260 0.000
L1.Salzburg 0.051388 0.028504 1.803 0.071
L1.Steiermark -0.007792 0.037313 -0.209 0.835
L1.Tirol 0.149600 0.030262 4.943 0.000
L1.Vorarlberg 0.070861 0.026019 2.723 0.006
L1.Wien 0.078812 0.047870 1.646 0.100
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.177515 0.047513 3.736 0.000
L1.Burgenland -0.005927 0.031979 -0.185 0.853
L1.Kärnten -0.061208 0.017028 -3.595 0.000
L1.Niederösterreich -0.083923 0.066884 -1.255 0.210
L1.Oberösterreich 0.192159 0.064160 2.995 0.003
L1.Salzburg 0.057160 0.034065 1.678 0.093
L1.Steiermark 0.230184 0.044593 5.162 0.000
L1.Tirol 0.494289 0.036166 13.667 0.000
L1.Vorarlberg 0.049699 0.031095 1.598 0.110
L1.Wien -0.047726 0.057210 -0.834 0.404
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.161839 0.054548 2.967 0.003
L1.Burgenland -0.011383 0.036714 -0.310 0.757
L1.Kärnten 0.065907 0.019549 3.371 0.001
L1.Niederösterreich 0.200318 0.076788 2.609 0.009
L1.Oberösterreich -0.061148 0.073661 -0.830 0.406
L1.Salzburg 0.216539 0.039109 5.537 0.000
L1.Steiermark 0.113516 0.051196 2.217 0.027
L1.Tirol 0.077268 0.041522 1.861 0.063
L1.Vorarlberg 0.124606 0.035700 3.490 0.000
L1.Wien 0.114569 0.065682 1.744 0.081
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.353441 0.031790 11.118 0.000
L1.Burgenland 0.005690 0.021396 0.266 0.790
L1.Kärnten -0.023597 0.011393 -2.071 0.038
L1.Niederösterreich 0.223835 0.044751 5.002 0.000
L1.Oberösterreich 0.175162 0.042929 4.080 0.000
L1.Salzburg 0.047462 0.022792 2.082 0.037
L1.Steiermark -0.016746 0.029837 -0.561 0.575
L1.Tirol 0.108962 0.024199 4.503 0.000
L1.Vorarlberg 0.073833 0.020805 3.549 0.000
L1.Wien 0.053184 0.038279 1.389 0.165
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.041256 0.152608 0.190048 0.157521 0.124411 0.113861 0.065629 0.226919
Kärnten 0.041256 1.000000 -0.002589 0.129772 0.041587 0.096016 0.429529 -0.053110 0.101141
Niederösterreich 0.152608 -0.002589 1.000000 0.336944 0.154520 0.300419 0.111134 0.183854 0.328102
Oberösterreich 0.190048 0.129772 0.336944 1.000000 0.232230 0.332666 0.172731 0.172506 0.262684
Salzburg 0.157521 0.041587 0.154520 0.232230 1.000000 0.145759 0.127197 0.149046 0.134447
Steiermark 0.124411 0.096016 0.300419 0.332666 0.145759 1.000000 0.153457 0.140964 0.079106
Tirol 0.113861 0.429529 0.111134 0.172731 0.127197 0.153457 1.000000 0.115117 0.155071
Vorarlberg 0.065629 -0.053110 0.183854 0.172506 0.149046 0.140964 0.115117 1.000000 0.007244
Wien 0.226919 0.101141 0.328102 0.262684 0.134447 0.079106 0.155071 0.007244 1.000000